# Contributor: Natanael Copa <ncopa@alpinelinux.org>
# Maintainer: Celeste <cielesti@protonmail.com>
maintainer="Celeste <cielesti@protonmail.com>"
pkgname=crosstool-ng
pkgver=1.26.0_git20240914
pkgrel=0
_gitrev=efcfd1abb6d7bc320ceed062352e0d5bebe6bf1f
pkgdesc="Versatile tool for building (cross-)toolchains"
url="https://crosstool-ng.github.io/"
license="LGPL-2.1-or-later GPL-2.0-or-later CC-BY-SA-2.5"
arch="all"
depends="
	autoconf
	automake
	bash
	bison
	cvs
	file
	flex
	g++
	gawk
	gperf
	libtool
	make
	patch
	rsync
	sed
	wget
	xz
	texinfo"
makedepends="ncurses-dev help2man xz gettext-dev"
subpackages="$pkgname-doc $pkgname-bash-completion"
#source="http://crosstool-ng.org/download/crosstool-ng/crosstool-ng-$pkgver.tar.xz
source="https://github.com/crosstool-ng/crosstool-ng/archive/$_gitrev/crosstool-ng-$_gitrev.tar.gz
	0001-sunrpc.diff
	"
builddir="$srcdir/$pkgname-$_gitrev"
options="!check" # FIXME: run tests if possible!

prepare() {
	default_prepare

	./bootstrap
}

build() {
	./configure --prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info
	make
}

package() {
	make DESTDIR="$pkgdir" install

	# bash completion
	mkdir -p "$pkgdir"/usr/share/bash-completion/completions/
	mv "$pkgdir"/usr/share/bash-completion/completions/ct-ng \
		"$pkgdir"/usr/share/bash-completion/completions/$pkgname

	# glibc patch
	for glibc in 2.28 2.29; do
		install -D -m 0644 "$srcdir"/0001-sunrpc.diff \
			"$pkgdir"/usr/share/crosstool-ng/packages/glibc/$glibc/0001-sunrpc.patch
	done
}

sha512sums="
7a3fda46c7f92509d4c9e413505d084e59bba5ecc06dc3e779cf73194de13b66b896f898eb7c6b521c1eee9080f8449276773e4530a56666a8b48e100b7b969b  crosstool-ng-efcfd1abb6d7bc320ceed062352e0d5bebe6bf1f.tar.gz
4ef553b1e5295924e86c8457fac7ad128107f97c7ea247246f89a626937906f67f9a734aa77dc438680c2ac4d684f74819f8fde105459de4402dc7315fffa805  0001-sunrpc.diff
"
